<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<html>
<head>
	<title>申请书管理</title>
	<meta name="decorator" content="default"/>
	<%@ include file="/WEB-INF/views/include/pdf.jsp"%>
	<%
		Object optObj = request.getAttribute("opt");
		String opt = null;
		if(optObj!=null){
			opt = (String)optObj;
		}
		if(opt!=null && opt.equals("detail")){ 
	%>
	 <script type="text/javascript">
		$(document).ready(function() {
			$(this).find("input").each(function() {
				$(this).attr("disabled", "disabled");
				}); 
			$(this).find("select").each(function() {
				$(this).attr("disabled", "disabled");
				});
		});
	</script>
	 <%
	 	}else{
	 %>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<%}%>
	
	<script type="text/javascript">
		function ajaxFileUpload(ipt,imgStr) {
		    //图片格式验证
		    var x = ipt;
		    if (!x || !x.value) return;
		    var patn = /\.pdf$|\.pdf$/i;
		    if (!patn.test(x.value)) {
		        alert("您选择的似乎不是图像文件。");
		        x.value = "";
		        return;
		    }
		    var elementIds = [ipt]; //flag为id、name属性名
		    var hiddenIpt = ipt.previousElementSibling;
		    $.ajaxFileUpload({
		        url: '${ctx}/file/upload?prePath=applayBook', 
		        type: 'post',
		        secureuri: false, //一般设置为false
		        fileElementId: ipt.id, // 上传文件的id、name属性名
		        dataType: 'json', //返回值类型，一般设置为json、application/json
		        elementIds: elementIds, //传递参数到服务器
		        success: function (data, status) {
		            if (data.status != 200) {
		                alert("文件太大，请上传不大于5M的文件！");
		                return;
		            }else {
		                //这里为上传并做一下请求显示处理，返回的data是对应上传的文件名
		            	hiddenIpt.value = data.data
		            	$('#preBut').css('display','inline');
		            }
		        },
		        error: function (data, status, e) {
		            alert(e);
		        }
		    });
		    //return false;
		}
		function viewPdf(){
			// If absolute URL from the remote server is provided, configure the CORS
			// header on that server.
			var url = $("#pdfIpt").val();
			$('#pdf_preview').attr("src",url);
			$('#pdf_preview').media(
			{
			  width : '100%',
			  height : '700px',
			  autoplay : true
			});
			$("#mymodal").modal('show');
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/applybook/bizApplyBook/form?id=${bizApplyBook.id}">申请书<shiro:hasPermission name="applybook:bizApplyBook:edit">${not empty bizApplyBook.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="applybook:bizApplyBook:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="bizApplyBook" action="${ctx}/applybook/bizApplyBook/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">申请标题：</label>
			<div class="controls">
				<form:input path="title" htmlEscape="false" maxlength="255" class="input-xlarge "/>
				<form:input path="categoryName" type="hidden"/>
				<form:input path="periodId" type="hidden"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">申请文件pdf：</label>
			<div class="controls">
				<button class="btn btn-sm" id="preBut" data-toggle="modal" style="${empty bizApplyBook.pdfUrl?'display:none':'' }" onclick="javascript:viewPdf('${bizApplyBook.pdfUrl}')" data-target="#myModal">预览附件</button>
				<form:hidden path="pdfUrl" id="pdfIpt" class="input-middle"/>
				<input type="file" name="picHeadIbg" id="picHeadIbg" onchange="ajaxFileUpload(this,'pdfUrlId')" class="input-middle"/>
				<input type="hidden" name="prePath" value="applyBook" >
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">分类：</label>
			<div class="controls">
				<sys:treeselect notAllowSelectParent="true" id="baseCategory" name="categoryId" value="${bizApplyBook.categoryId}" labelName="categoryName" labelValue="${bizApplyBook.categoryName}"
					title="分类" url="/category/baseCategory/treeData"  disabled="disabled" cssClass="required" allowClear="true" />
					<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">申请类别：</label>
			<div class="controls">
				<form:hidden path="applyType"/>
				${fns:getDictLabel(bizApplyBook.applyType, 'apply_type', '')}
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">申请内容：</label>
			<div class="controls">
				<form:textarea path="content" htmlEscape="false" rows="4" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="applybook:bizApplyBook:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" style="max-height:100%;height:100%"   aria-labelledby="myModalLabel" aria-hidden="true" >
		<div class="modal-dialog"  style="max-height:100%;height:100%">
			<div class="modal-content"  style="max-height:100%;height:100%"> 
				<div class="modal-body"  style="max-height:100%;height:80%">
					<div id="pdf_preview"></div>
				</div>
				<div class="modal-footer" style="height:20%">
					<button type="button" class="btn btn-default" data-dismiss="modal" id="guideCloseBut">关闭</button>
				</div>
			</div>
		</div>
		<!-- /.modal -->
	</div>
</body>
</html>